package dto

import (
	"time"
	"vrcm/src/vrcm/app/admin/models/domian"
	"vrcm/src/vrcm/common/dto"
	common "vrcm/src/vrcm/common/models"
)

type DomainConfigGetPageReq struct {
	dto.Pagination `search:"-"`
	TenantId       string `json:"tenant_id"  search:"type:exact;column:tenant_id;table:domain_config"`
	AcDomain       string `json:"ac_domain"  search:"type:contains;column:ac_domain;table:domain_config"`
	ZoneId         string `json:"zone_id"  search:"type:exact;column:zone_id;table:domain_config"`
	AcArea         int    `json:"ac_area"  search:"type:exact;column:ac_area;table:domain_config"`
	AcType         int    `json:"ac_type"  search:"type:exact;column:ac_type;table:domain_config"`
	DomainState    int    `json:"domain_state"  search:"type:exact;column:domain_state;table:domain_config"`
}

type DomainConfigOrder struct {
	TenantId string `json:"tenant_id"  search:"type:exact;column:tenant_id;table:domain_config"`
	AcDomain string `json:"ac_domain"  search:"type:order;column:ac_domain;table:domain_config"`
}

func (m *DomainConfigGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type DomainConfigInsertReq struct {
	Id                     int                          `json:"-" comment:""` //
	TenantId               string                       `json:"tenant_id" comment:"租户"`
	AcDomain               string                       `json:"ac_domain" comment:"加速域名"`
	AcType                 int                          `json:"ac_type" comment:"加速类型 1网页小文件 2大文件下载 3音视频点播 4hls直播"`
	AcArea                 int                          `json:"ac_area" comment:"加速区域 境内 2境外 3全球"`
	Range                  int                          `json:"range" comment:"1启用 0禁用"`
	Host                   string                       `json:"host" comment:"1启用 0禁用"`
	Area                   string                       `json:"area" gorm:"type:varchar(100);comment:回源区域"`
	BackSourceConfig       domain.BackSourceConfig      `json:"back_source_config" comment:"回源配置"`
	SourceStationAddresses []domain.SourceStationConfig `json:"source_station_addresses"  comment:"原站地址"`
	common.ControlBy
}

func (s *DomainConfigInsertReq) Generate(model *domain.DomainConfig) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	now := time.Now().Unix()
	model.TenantId = s.TenantId
	model.AcDomain = s.AcDomain
	model.AcType = s.AcType
	model.AcArea = s.AcArea
	model.CreateBy = s.CreateBy
	model.DomainState = 1
	model.Range = s.Range
	model.CreateTime = now
	model.UpdateTime = now

}

func (s *DomainConfigInsertReq) GetId() interface{} {
	return s.Id
}

type DomainConfigUpdateReq struct {
	domain.DomainConfigModel
	Id                     int                            `json:"id" comment:""` //
	TenantId               string                         `json:"tenant_id" comment:"租户"`
	AcDomain               string                         `json:"ac_domain" comment:"加速域名"`
	AcType                 int                            `json:"ac_type" comment:"加速类型 1网页小文件 2大文件下载 3音视频点播 4hls直播"`
	AcArea                 int                            `json:"ac_area" comment:"加速区域 境内 2境外 3全球"`
	Range                  int                            `json:"range" comment:"1启用 0禁用"`
	BackSourceConfig       *domain.BackSourceConfig       `json:"back_source_config" comment:"回源配置"`
	SourceStationAddresses *[]domain.SourceStationConfig  `json:"source_station_addresses"  comment:"原站地址"`
	UrlSign                *UrlSignSaveReq                `json:"url_sign"  comment:"url鉴权"`
	CacheFilterConfig      *MultiCacheFilterConfigSaveReq `json:"cache_filter_config"  comment:"缓存过滤配置"`
	CacheExpireConfig      *MultiCacheExpireConfigSaveReq `json:"cache_expire_config"  comment:"缓存过期配置"`
	DistributionProtocol   *DistributionProtocolSaveReq   `json:"distribution_protocol"  comment:"分发协议"`
	//Certificate            *domain.Certificate                `json:"certificate" comment:"证书"`
	StateCodeExpireConfig *MultiStateCodeExpireConfigSaveReq `json:"state_code_expire_config" comment:"状态码过期"`
	AntiTheftConfig       *AntiTheftConfigSaveReq            `json:"anti_theft_config" comment:"防盗链配置"`
	//OverWriteUrls          *[]domain.OverWriteUrl             `json:"over_write_urls" comment:"重写url"`
	HeaderConfigs  *MultiHeaderConfigSaveReq `json:"header_configs" comment:"头部配置"`
	CompressConfig *CompressConfigSaveReq    `json:"compress" comment:"压缩配置"`
	common.ControlBy
}

//func (s *DomianConfigUpdateReq) Generate(model *domain.DomainConfig) {
//	if s.Id == 0 {
//		model.Model = common.Model{Id: s.Id}
//	}
//	model.TenantId = s.TenantId
//	model.AcDomain = s.AcDomain
//	model.AcType = s.AcType
//	model.AcArea = s.AcArea
//	model.Cname = s.Cname
//	model.DomainState = s.DomainState
//	model.CreateTime = s.CreateTime
//	model.UpdateTime = s.UpdateTime
//	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
//}
//
//func (s *DomianConfigUpdateReq) GetId() interface{} {
//	return s.Id
//}

// DomainConfigGetReq  功能获取请求参数
type DomainConfigGetReq struct {
	Id int `uri:"id"`
}

func (s *DomainConfigGetReq) GetId() interface{} {
	return s.Id
}

// DomainConfigDeleteReq 功能删除请求参数
type DomainConfigDeleteReq struct {
	Ids []int `json:"ids"`
}

func (s *DomainConfigDeleteReq) GetId() interface{} {
	return s.Ids
}

type SourceStationConfigSaveReq struct {
	Id              int    `json:"id"`
	TenantId        string `json:"tenant_id"`
	DomainId        int    `json:"domain_id"`
	SourceStationIp string `json:"source_station_ip"`
	Port            string `json:"port"`
	Priority        int    `json:"priority"`
	Weight          int    `json:"weight"`
}

type SourceStationConfigDeleteReq struct {
	Id       int `json:"id"`
	DomainId int `json:"domain_id"`
}

type BackSourceConfigSaveReq struct {
	DomainId    int `json:"domain_id"`
	EnableTrace int `json:"enable_trace"`
}

type CacheExpireConfigSaveReq struct {
	Id         int    `json:"id"`
	TenantId   string `json:"tenant_id"`
	DomainId   int    `json:"domain_id"`
	ExpireType int    `json:"expire_type"`
	Content    string `json:"content"`
	ExpireTime int    `json:"expire_time"`
	Unit       int    `json:"unit"`
	CacheSet   int    `json:"cache_set"`
	Sort       int    `json:"sort"`
	Priority   int    `json:"priority"`
}

type MultiCacheExpireConfigSaveReq struct {
	DomainId int                        `json:"domain_id"`
	Params   []CacheExpireConfigSaveReq `json:"params"`
}

type StateCodeExpireConfigSaveReq struct {
	Id         int    `json:"id"`
	TenantId   string `json:"tenant_id"`
	DomainId   int    `json:"domain_id"`
	ExpireTime int    `json:"expire_time" gorm:"type:int;comment:过期时间"`
	StateCode  string `json:"state_code" gorm:"type:varchar(100);comment:状态码"`
}

type MultiStateCodeExpireConfigSaveReq struct {
	DomainId int                            `json:"domain_id"`
	Params   []StateCodeExpireConfigSaveReq `json:"params" comment:"参数"`
}

type CacheExpireConfigDeleteReq struct {
	Id       int `json:"id"`
	DomainId int `json:"domain_id"`
}

type StateCodeExpireConfigDeleteReq struct {
	Id       int `json:"id"`
	DomainId int `json:"domain_id"`
}

type CacheFilterConfigSaveReq struct {
	Id           int    `json:"id"`
	TenantId     string `json:"tenant_id"`
	DomainId     int    `json:"domain_id"`
	IgnoreFilter int    `json:"ignore_filter"`
	FilterParam  string `json:"filter_param"`
	ExpireType   int    `json:"expire_type"`
	Content      string `json:"content"`
	IgnoreCase   int    `json:"ignore_case"`
	Sort         int    `json:"sort"`
	Priority     int    `json:"priority"`
}

type MultiCacheFilterConfigSaveReq struct {
	DomainId int                        `json:"domain_id"`
	Params   []CacheFilterConfigSaveReq `json:"params"`
}

type CacheFilterConfigDeleteReq struct {
	Id       int `json:"id"`
	DomainId int `json:"domain_id"`
}

type DistributionProtocolSaveReq struct {
	Id           int    `json:"id"`
	TenantId     string `json:"tenant_id"`
	DomainId     int    `json:"domain_id"`
	EnableHttps  int    `json:"enable_https"`
	EnableQuic   int    `json:"enable_quic"`
	ForceJump    int    `json:"force_jump"`
	EnableHttp2  int    `json:"enable_http2"`
	RedirectCode int    `json:"redirect_code"`
	TlsVersion   string `json:"tls_version"`
}

type DistributionProtocolDeleteReq struct {
	Id       int `json:"id"`
	DomainId int `json:"domain_id"`
}

type StartDomainReq struct {
	Id       int    `json:"id"`
	TenantId string `json:"tenant_id"`
}

type StopDomainReq struct {
	Id       int    `json:"id"`
	TenantId string `json:"tenant_id"`
}

type UpOrDownReq struct {
	Id   int `json:"id"`
	Type int `json:"type"`
}

type AntiTheftConfigSaveReq struct {
	Id                 int    `json:"id"`
	TenantId           string `json:"tenant_id"`
	DomainId           int    `json:"domain_id"`
	EnableWhite        string `json:"enable_white" comment:"yse启用 no禁用"`
	EnableBlack        string `json:"enable_black" comment:"yse启用 no禁用"`
	WhiteList          string `json:"white_list" comment:"白名单"`
	BlackList          string `json:"black_list" comment:"黑名单"`
	EnableIpController string `json:"enable_ip_control" comment:"1启用 0禁用"`
	EnableUaController string `json:"enable_ua_control" comment:"1启用 0禁用"`
	IpType             string `json:"ip_type" comment:"white 白名单 black 黑名单"`
	UaType             string `json:"ua_type" comment:"white 白名单 black 黑名单"`
	IpList             string `json:"ip_list" comment:"ip控制名单"`
	UaList             string `json:"ua_list" comment:"ua控制名单"`
	IncludeEmpty       int    `json:"include_empty" gorm:"type:tinyint;comment:1包含空 0不包含"`
}

type UrlSignSaveReq struct {
	Id             int    `json:"id"`
	TenantId       string `json:"tenant_id"`
	DomainId       int    `json:"domain_id"`
	SignStatus     string `json:"sign_status"`
	SignType       string `json:"sign_type" gorm:"type:varchar(50);comment:type_a-方式A\ntype_b-方式B\ntype_c1-方式C1\ntype_c2-方"`
	SignMethod     string `json:"sign_method"`
	Keys           string `json:"keys"`
	SessionTimeout string `json:"session_timeout"`
	SignArg        string `json:"sign_arg"`
}
type MultiHeaderConfigSaveReq struct {
	DomainId   int                   `json:"domain_id"`
	Params     []HeaderConfigSaveReq `json:"params" comment:"参数"`
	HeaderType int                   `json:"header_type" comment:"1 request 2 response"`
}

type HeaderConfigSaveReq struct {
	Id           int    `json:"id"`
	TenantId     string `json:"tenant_id"`
	HeaderKey    string `json:"header_key" gorm:"type:varchar(100);comment:头部key"`
	HeaderValue  string `json:"header_value" gorm:"type:varchar(100);comment:头部value"`
	OperatorType string `json:"operator_type" gorm:"type:varchar(20);comment:操作类型1 add 2 remove"`
	HeaderType   int    `json:"header_type" gorm:"type:tinyint;comment:1 request 2 response"`
}

type HeaderConfigDeleteReq struct {
	DomainId int `json:"domain_id"`
}

type CompressConfigSaveReq struct {
	Id            int    `json:"id"`
	TenantId      string `json:"tenant_id" comment:"租户"`
	DomainId      int    `json:"domain_id" comment:"DomainId"`
	CompressState string `json:"compress_state" comment:"压缩状态 on off"`
	CompressType  string `json:"compress_type" comment:"压缩类型 gzip,br逗号分隔"`
	FileType      string `json:"file_type" comment:"文件类型分号分割"`
}
